﻿namespace Example.Views.Shared
{
    using System.Web.Mvc;
    using System.Xml.XPath;

    using Cavity;
    using Cavity.Xml.XPath;

    using RazorGenerator.Testing;

    using Xunit;
    using Xunit.Extensions;

    public sealed class ErrorFacts
    {
        [Fact]
        public void a_definition()
        {
            Assert.True(new TypeExpectations<Error>()
                            .DerivesFrom<WebViewPage<dynamic>>()
                            .IsConcreteClass()
                            .IsUnsealed()
                            .HasDefaultConstructor()
                            .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new Error());
        }

        [Theory]
        [InlineData("1 = count(/html)")]
        [InlineData("1 = count(/html/head)")]
        [InlineData("1 = count(/html/body)")]
        public void html(string xpath)
        {
            Assert.True(render().Evaluate<bool>(xpath));
        }

        [Theory]
        [InlineData("0 = count(//link)")]
        public void links(string xpath)
        {
            Assert.True(render().Evaluate<bool>(xpath));
        }

        [Theory]
        [InlineData("0 = count(//script)")]
        public void scripts(string xpath)
        {
            Assert.True(render().Evaluate<bool>(xpath));
        }

        [Theory]
        [InlineData("1 = count(//title)")]
        [InlineData("1 = count(/html/head/title[text()='Error'])")]
        [InlineData("1 = count(//h1)")]
        [InlineData("1 = count(//h1[@id='title'][text()='Error'])")]
        public void title(string xpath)
        {
            Assert.True(render().Evaluate<bool>(xpath));
        }

        private static XPathNavigator render()
        {
            return new Error().RenderAsHtml().CreateNavigator();
        }
    }
}